package com.xiaoaoc.SmartToilet.controller;


import com.xiaoaoc.SmartToilet.dto.ApiResponse;
import com.xiaoaoc.SmartToilet.model.Toilet;
import com.xiaoaoc.SmartToilet.repository.ToiletRepository;
import com.xiaoaoc.SmartToilet.service.ToiletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/toilet")
public class ToiletController {
    @Autowired
    private ToiletService toiletservice;

    @PostMapping("/add")
    public ResponseEntity<ApiResponse<Toilet>> createToilet(@RequestBody Toilet toilet) {
        Toilet createdToilet = toiletservice.createToilet(toilet);
        return ResponseEntity.status(HttpStatus.CREATED).body(new ApiResponse<>(createdToilet));
    }

    @PostMapping("/get-all")
    public ResponseEntity<ApiResponse<List<Toilet>>> getAll(){
        List<Toilet> toilets = toiletservice.getAllToilets();
        return ResponseEntity.status(HttpStatus.OK).body(new ApiResponse<>(toilets));
    }
}
